#ifndef _TYPE_PARSER_H_
#define _TYPE_PARSER_H_

#include <string>
#include <fan-llvm/SysPod.h>


/**
 * TypeParser is used to parse and load types from the corresponding pod, according to their signatures.
 * Signatures are formated as (with arbitrary nesting):
 *
 *   x::N
 *   x::V[]
 *   x::V[x::K]
 *   |x::A, ... -> x::R|
 */
class TypeParser
{
public:
  static Type* load(const std::string& sig, bool checked, Pod* loadingPod);
  static Type* find(const std::string& podName, const std::string& typeName, bool checked);

private:
  TypeParser(const std::string& sig, bool checked, Pod* loadingPod);
  Type* loadTop();
  Type* load();
  Type* loadMap();
  Type* loadFunc();
  Type* loadBasic();
  std::string consumeId();
  void consume(char expected);
  void consume();
  Err* err();
  static Err* err(const std::string& sig);

  std::string m_sig;
  size_t m_len;
  size_t m_pos;
  char m_cur;
  char m_peek;
  bool m_checked;
  Pod* m_loadingPod;
};


#endif
